package com.meshnetics.gb.stack.core.event;

import com.meshnetics.gb.Context;
import com.meshnetics.gb.stack.core.StackStatus;
import com.meshnetics.gb.stack.core.layer.StackLayer;

/**
 * Base class for all stack confirm events.
 *
 * @author mmarkov
 */
public class StackConfirm extends StackEvent {

    private StackStatus status;

    /**
     * Constructs StackConfirm having the given name and type and no Context.
     *
     * @param name   the name of StackConfirm
     * @param type   the type of StackConfirm
     * @param status the status of StackConfirm
     */
    public StackConfirm(String name, StackEventType type, StackStatus status) {
        super(name, type, null);
        this.status = status;
    }

    public StackConfirm(String name, StackEventType type) {
        this(name, type, null);
    }

    protected void setStatus(StackStatus status) {
        this.status = status;
    }

    /**
     * Constructs StackConfirm having the given name, type and context.
     *
     * @param name   the name of StackConfirm
     * @param type   the type of StackConfirm
     * @param status the status of StackConfirm
     * @param ctx    the Context of StackConfirm (could be null)
     */
    public StackConfirm(String name, StackEventType type, StackStatus status, Context ctx) {
        this(name, type, status, ctx, null);
    }

    /**
     * Creates StackEvent with given name, type, context and source.
     *
     * @param name   the name of StackEvent
     * @param type   the type of StackEvent
     * @param status the status of StackConfirm
     * @param ctx    the Context of StackEvent (could be null)
     * @param source the source of event (can be null)
     */
    public StackConfirm(String name, StackEventType type, StackStatus status, Context ctx, StackLayer source) {
        super(name, type, ctx, source);
        this.status = status;
    }

    /**
     * Returns the status of this StackConfirm.
     *
     * @return the status of this StackConfirm
     */
    public StackStatus getStatus() {
        return status;
    }

    /**
     * Returns string representation of this StackConfirm, i.e. it's name and status.
     *
     * @return string representation of this StackConfirm, i.e. it's name and status
     */
    public String toString() {
        return super.toString() + ", status= " + status;
    }
}
